<?php

/**
 * Grouping applications data by time
 * @status TESTED in (rev123), NOT_APPROVED
 */
class TimeGroup {
    public $date;
    public $subdivision = '';
    
    public $applications = array();
    public $predicted = false;
    
    public $sum_administrated = 0;
    public $predicted_administrated = 0;
    
    public $sum_time = 0;
    public $predicted_time = 0;
    
    function __construct($date, $predicted = false, $subdivision = '') {
        $this->date = $date;
        $this->predicted = $predicted;
        $this->subdivision = $subdivision;
    }
            
    public function sum_administrated() {
        if ($this->predicted) {
            return $this->predicted_administrated;
        } else if ($this->sum_administrated) {
            return $this->sum_administrated;
        } else {
            $sum = 0;
            foreach ($this->applications as $application) {
                $sum += $application->administrated;
            }
            return $sum;
        }
    }
    
    public function sum_time_used() {
        if ($this->predicted) {
            return $this->predicted_time;
        } else if ($this->sum_time) {
            return $this->sum_time;
        } else {
            $sum = 0;
            foreach ($this->applications as $application) {
                $sum += $application->get_time_administrated();
            }
            return $sum;
        }
    }
}